home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Font Fun / EmbossedText / EmbossedText.cs next >
Encoding:
Text File  |  2001-01-15  |  1.4 KB  |  44 lines

  1. //-------------------------------------------
  2. // EmbossedText.cs ⌐ 2001 by Charles Petzold
  3. //-------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class EmbossedText: FontMenuForm
  9. {
  10.      int iOffset = 2;
  11.  
  12.      public new static void Main()
  13.      {
  14.           Application.Run(new EmbossedText());
  15.      }
  16.      public EmbossedText()
  17.      {
  18.           Text = "Embossed Text";
  19.           Width *= 2;
  20.           Menu.MenuItems.Add("&Toggle!", 
  21.                                    new EventHandler(MenuToggleOnClick));
  22.           strText = "Emboss";
  23.           font = new Font("Times New Roman", 108);
  24.      }
  25.      void MenuToggleOnClick(object obj, EventArgs ea)
  26.      {
  27.           iOffset = -iOffset;
  28.           Text = (iOffset > 0) ? "Embossed Text" : "Engraved Text";
  29.           strText = (iOffset > 0) ? "Emboss" : "Engrave";
  30.           Invalidate();
  31.      }
  32.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  33.      {
  34.           SizeF sizef = grfx.MeasureString(strText, font);
  35.           float x     = (cx - sizef.Width) / 2;
  36.           float y     = (cy - sizef.Height) / 2;
  37.  
  38.           grfx.Clear(Color.White);
  39.           grfx.DrawString(strText, font, Brushes.Gray, x, y);
  40.           grfx.DrawString(strText, font, Brushes.White, x - iOffset, 
  41.                                                         y - iOffset);
  42.      }
  43. }
  44.